#include <iostream>
#include <boost/asio.hpp>
#include <array>

using namespace boost::asio;
using boost::asio::ip::udp;

int main(int argc, char const *argv[])
{
    try
    {
        if (argc != 2)
        {
            std::cerr << "Usage: client <host>" << '\n';
            return 1;
        }
        io_service           io_service;
        udp::resolver        resolver(io_service);
        udp::resolver::query query(udp::v4(), argv[1], "12345");
        udp::endpoint        receiver_endpoint = *resolver.resolve(query);

        udp::socket socket(io_service);
        socket.open(udp::v4());

        std::array<char, 1> send_buf = {{0}};
        socket.send_to(buffer(send_buf), receiver_endpoint);

        std::array<char, 128> recv_buf;
        udp::endpoint         sender_endpoint;
        size_t                len = socket.receive_from(buffer(recv_buf), sender_endpoint);
        std::cout.write(recv_buf.data(), len);
    }
    catch (const std::exception &e)
    {
        std::cerr << e.what() << '\n';
    }

    return 0;
}
